<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>modalpopup.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_modalpopup.js.html">modalpopup.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Class for showing simple modal popup.
<a name="line17"></a> */
<a name="line18"></a>
<a name="line19"></a>goog.provide(&#39;goog.ui.ModalPopup&#39;);
<a name="line20"></a>
<a name="line21"></a>goog.require(&#39;goog.Timer&#39;);
<a name="line22"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line23"></a>goog.require(&#39;goog.dom&#39;);
<a name="line24"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line25"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line26"></a>goog.require(&#39;goog.dom.iframe&#39;);
<a name="line27"></a>goog.require(&#39;goog.events&#39;);
<a name="line28"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line29"></a>goog.require(&#39;goog.events.FocusHandler&#39;);
<a name="line30"></a>goog.require(&#39;goog.fx.Transition&#39;);
<a name="line31"></a>goog.require(&#39;goog.style&#39;);
<a name="line32"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line33"></a>goog.require(&#39;goog.ui.PopupBase.EventType&#39;);
<a name="line34"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * Base class for modal popup UI components. This can also be used as
<a name="line40"></a> * a standalone component to render a modal popup with an empty div.
<a name="line41"></a> *
<a name="line42"></a> * WARNING: goog.ui.ModalPopup is only guaranteed to work when it is rendered
<a name="line43"></a> * directly in the &#39;body&#39; element.
<a name="line44"></a> *
<a name="line45"></a> * The Html structure of the modal popup is:
<a name="line46"></a> * &lt;pre&gt;
<a name="line47"></a> *  Element         Function              Class-name, goog-modalpopup = default
<a name="line48"></a> * ----------------------------------------------------------------------------
<a name="line49"></a> * - iframe         Iframe mask           goog-modalpopup-bg
<a name="line50"></a> * - div            Background mask       goog-modalpopup-bg
<a name="line51"></a> * - div            Modal popup area      goog-modalpopup
<a name="line52"></a> * - span           Tab catcher
<a name="line53"></a> * &lt;/pre&gt;
<a name="line54"></a> * @constructor
<a name="line55"></a> * @param {boolean=} opt_useIframeMask Work around windowed controls z-index
<a name="line56"></a> *     issue by using an iframe instead of a div for bg element.
<a name="line57"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper; see {@link
<a name="line58"></a> *     goog.ui.Component} for semantics.
<a name="line59"></a> * @extends {goog.ui.Component}
<a name="line60"></a> */
<a name="line61"></a>goog.ui.ModalPopup = function(opt_useIframeMask, opt_domHelper) {
<a name="line62"></a>  goog.base(this, opt_domHelper);
<a name="line63"></a>
<a name="line64"></a>  /**
<a name="line65"></a>   * Whether the modal popup should use an iframe as the background
<a name="line66"></a>   * element to work around z-order issues.
<a name="line67"></a>   * @type {boolean}
<a name="line68"></a>   * @private
<a name="line69"></a>   */
<a name="line70"></a>  this.useIframeMask_ = !!opt_useIframeMask;
<a name="line71"></a>};
<a name="line72"></a>goog.inherits(goog.ui.ModalPopup, goog.ui.Component);
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * Focus handler. It will be initialized in enterDocument.
<a name="line77"></a> * @type {goog.events.FocusHandler}
<a name="line78"></a> * @private
<a name="line79"></a> */
<a name="line80"></a>goog.ui.ModalPopup.prototype.focusHandler_ = null;
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>/**
<a name="line84"></a> * Whether the modal popup is visible.
<a name="line85"></a> * @type {boolean}
<a name="line86"></a> * @private
<a name="line87"></a> */
<a name="line88"></a>goog.ui.ModalPopup.prototype.visible_ = false;
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * Element for the background which obscures the UI and blocks events.
<a name="line93"></a> * @type {Element}
<a name="line94"></a> * @private
<a name="line95"></a> */
<a name="line96"></a>goog.ui.ModalPopup.prototype.bgEl_ = null;
<a name="line97"></a>
<a name="line98"></a>
<a name="line99"></a>/**
<a name="line100"></a> * Iframe element that is only used for IE as a workaround to keep select-type
<a name="line101"></a> * elements from burning through background.
<a name="line102"></a> * @type {Element}
<a name="line103"></a> * @private
<a name="line104"></a> */
<a name="line105"></a>goog.ui.ModalPopup.prototype.bgIframeEl_ = null;
<a name="line106"></a>
<a name="line107"></a>
<a name="line108"></a>/**
<a name="line109"></a> * Element used to catch focus and prevent the user from tabbing out
<a name="line110"></a> * of the popup.
<a name="line111"></a> * @type {Element}
<a name="line112"></a> * @private
<a name="line113"></a> */
<a name="line114"></a>goog.ui.ModalPopup.prototype.tabCatcherElement_ = null;
<a name="line115"></a>
<a name="line116"></a>
<a name="line117"></a>/**
<a name="line118"></a> * Whether the modal popup is in the process of wrapping focus from the top of
<a name="line119"></a> * the popup to the last tabbable element.
<a name="line120"></a> * @type {boolean}
<a name="line121"></a> * @private
<a name="line122"></a> */
<a name="line123"></a>goog.ui.ModalPopup.prototype.backwardTabWrapInProgress_ = false;
<a name="line124"></a>
<a name="line125"></a>
<a name="line126"></a>/**
<a name="line127"></a> * Transition to show the popup.
<a name="line128"></a> * @type {goog.fx.Transition}
<a name="line129"></a> * @private
<a name="line130"></a> */
<a name="line131"></a>goog.ui.ModalPopup.prototype.popupShowTransition_;
<a name="line132"></a>
<a name="line133"></a>
<a name="line134"></a>/**
<a name="line135"></a> * Transition to hide the popup.
<a name="line136"></a> * @type {goog.fx.Transition}
<a name="line137"></a> * @private
<a name="line138"></a> */
<a name="line139"></a>goog.ui.ModalPopup.prototype.popupHideTransition_;
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Transition to show the background.
<a name="line144"></a> * @type {goog.fx.Transition}
<a name="line145"></a> * @private
<a name="line146"></a> */
<a name="line147"></a>goog.ui.ModalPopup.prototype.bgShowTransition_;
<a name="line148"></a>
<a name="line149"></a>
<a name="line150"></a>/**
<a name="line151"></a> * Transition to hide the background.
<a name="line152"></a> * @type {goog.fx.Transition}
<a name="line153"></a> * @private
<a name="line154"></a> */
<a name="line155"></a>goog.ui.ModalPopup.prototype.bgHideTransition_;
<a name="line156"></a>
<a name="line157"></a>
<a name="line158"></a>/**
<a name="line159"></a> * @return {string} Base CSS class for this component.
<a name="line160"></a> * @protected
<a name="line161"></a> */
<a name="line162"></a>goog.ui.ModalPopup.prototype.getCssClass = function() {
<a name="line163"></a>  return goog.getCssName(&#39;goog-modalpopup&#39;);
<a name="line164"></a>};
<a name="line165"></a>
<a name="line166"></a>
<a name="line167"></a>/**
<a name="line168"></a> * Returns the background iframe mask element, if any.
<a name="line169"></a> * @return {Element} The background iframe mask element, may return
<a name="line170"></a> *     null/undefined if the modal popup does not use iframe mask.
<a name="line171"></a> */
<a name="line172"></a>goog.ui.ModalPopup.prototype.getBackgroundIframe = function() {
<a name="line173"></a>  return this.bgIframeEl_;
<a name="line174"></a>};
<a name="line175"></a>
<a name="line176"></a>
<a name="line177"></a>/**
<a name="line178"></a> * Returns the background mask element.
<a name="line179"></a> * @return {Element} The background mask element.
<a name="line180"></a> */
<a name="line181"></a>goog.ui.ModalPopup.prototype.getBackgroundElement = function() {
<a name="line182"></a>  return this.bgEl_;
<a name="line183"></a>};
<a name="line184"></a>
<a name="line185"></a>
<a name="line186"></a>/**
<a name="line187"></a> * Creates the initial DOM representation for the modal popup.
<a name="line188"></a> * @override
<a name="line189"></a> */
<a name="line190"></a>goog.ui.ModalPopup.prototype.createDom = function() {
<a name="line191"></a>  // Create the modal popup element, and make sure it&#39;s hidden.
<a name="line192"></a>  goog.base(this, &#39;createDom&#39;);
<a name="line193"></a>
<a name="line194"></a>  var element = this.getElement();
<a name="line195"></a>  goog.dom.classes.add(element, this.getCssClass());
<a name="line196"></a>  goog.dom.setFocusableTabIndex(element, true);
<a name="line197"></a>  goog.style.showElement(element, false);
<a name="line198"></a>
<a name="line199"></a>  // Manages the DOM for background mask elements.
<a name="line200"></a>  this.manageBackgroundDom_();
<a name="line201"></a>  this.createTabCatcher_();
<a name="line202"></a>};
<a name="line203"></a>
<a name="line204"></a>
<a name="line205"></a>/**
<a name="line206"></a> * Creates and disposes of the DOM for background mask elements.
<a name="line207"></a> * @private
<a name="line208"></a> */
<a name="line209"></a>goog.ui.ModalPopup.prototype.manageBackgroundDom_ = function() {
<a name="line210"></a>  if (this.useIframeMask_ &amp;&amp; !this.bgIframeEl_) {
<a name="line211"></a>    // IE renders the iframe on top of the select elements while still
<a name="line212"></a>    // respecting the z-index of the other elements on the page.  See
<a name="line213"></a>    // http://support.microsoft.com/kb/177378 for more information.
<a name="line214"></a>    // Flash and other controls behave in similar ways for other browsers
<a name="line215"></a>    this.bgIframeEl_ = goog.dom.iframe.createBlank(this.getDomHelper());
<a name="line216"></a>    this.bgIframeEl_.className = goog.getCssName(this.getCssClass(), &#39;bg&#39;);
<a name="line217"></a>    goog.style.showElement(this.bgIframeEl_, false);
<a name="line218"></a>    goog.style.setOpacity(this.bgIframeEl_, 0);
<a name="line219"></a>  }
<a name="line220"></a>
<a name="line221"></a>  // Create the backgound mask, initialize its opacity, and make sure it&#39;s
<a name="line222"></a>  // hidden.
<a name="line223"></a>  if (!this.bgEl_) {
<a name="line224"></a>    this.bgEl_ = this.getDomHelper().createDom(
<a name="line225"></a>        &#39;div&#39;, goog.getCssName(this.getCssClass(), &#39;bg&#39;));
<a name="line226"></a>    goog.style.showElement(this.bgEl_, false);
<a name="line227"></a>  }
<a name="line228"></a>};
<a name="line229"></a>
<a name="line230"></a>
<a name="line231"></a>/**
<a name="line232"></a> * Creates the tab catcher element.
<a name="line233"></a> * @private
<a name="line234"></a> */
<a name="line235"></a>goog.ui.ModalPopup.prototype.createTabCatcher_ = function() {
<a name="line236"></a>  // Creates tab catcher element.
<a name="line237"></a>  if (!this.tabCatcherElement_) {
<a name="line238"></a>    this.tabCatcherElement_ = this.getDomHelper().createElement(&#39;span&#39;);
<a name="line239"></a>    goog.style.showElement(this.tabCatcherElement_, false);
<a name="line240"></a>    goog.dom.setFocusableTabIndex(this.tabCatcherElement_, true);
<a name="line241"></a>    this.tabCatcherElement_.style.position = &#39;absolute&#39;;
<a name="line242"></a>  }
<a name="line243"></a>};
<a name="line244"></a>
<a name="line245"></a>
<a name="line246"></a>/**
<a name="line247"></a> * Allow a shift-tab from the top of the modal popup to the last tabbable
<a name="line248"></a> * element by moving focus to the tab catcher. This should be called after
<a name="line249"></a> * catching a wrapping shift-tab event and before allowing it to propagate, so
<a name="line250"></a> * that focus will land on the last tabbable element before the tab catcher.
<a name="line251"></a> * @protected
<a name="line252"></a> */
<a name="line253"></a>goog.ui.ModalPopup.prototype.setupBackwardTabWrap = function() {
<a name="line254"></a>  this.backwardTabWrapInProgress_ = true;
<a name="line255"></a>  try {
<a name="line256"></a>    this.tabCatcherElement_.focus();
<a name="line257"></a>  } catch (e) {
<a name="line258"></a>    // Swallow this. IE can throw an error if the element can not be focused.
<a name="line259"></a>  }
<a name="line260"></a>  // Reset the flag on a timer in case anything goes wrong with the followup
<a name="line261"></a>  // event.
<a name="line262"></a>  goog.Timer.callOnce(this.resetBackwardTabWrap_, 0, this);
<a name="line263"></a>};
<a name="line264"></a>
<a name="line265"></a>
<a name="line266"></a>/**
<a name="line267"></a> * Resets the backward tab wrap flag.
<a name="line268"></a> * @private
<a name="line269"></a> */
<a name="line270"></a>goog.ui.ModalPopup.prototype.resetBackwardTabWrap_ = function() {
<a name="line271"></a>  this.backwardTabWrapInProgress_ = false;
<a name="line272"></a>};
<a name="line273"></a>
<a name="line274"></a>
<a name="line275"></a>/**
<a name="line276"></a> * Renders the background mask.
<a name="line277"></a> * @private
<a name="line278"></a> */
<a name="line279"></a>goog.ui.ModalPopup.prototype.renderBackground_ = function() {
<a name="line280"></a>  goog.asserts.assert(!!this.bgEl_, &#39;Background element must not be null.&#39;);
<a name="line281"></a>  if (this.bgIframeEl_) {
<a name="line282"></a>    goog.dom.insertSiblingBefore(this.bgIframeEl_, this.getElement());
<a name="line283"></a>  }
<a name="line284"></a>  goog.dom.insertSiblingBefore(this.bgEl_, this.getElement());
<a name="line285"></a>};
<a name="line286"></a>
<a name="line287"></a>
<a name="line288"></a>/** @override */
<a name="line289"></a>goog.ui.ModalPopup.prototype.canDecorate = function(element) {
<a name="line290"></a>  // Assume we can decorate any DIV.
<a name="line291"></a>  return !!element &amp;&amp; element.tagName == goog.dom.TagName.DIV;
<a name="line292"></a>};
<a name="line293"></a>
<a name="line294"></a>
<a name="line295"></a>/** @override */
<a name="line296"></a>goog.ui.ModalPopup.prototype.decorateInternal = function(element) {
<a name="line297"></a>  // Decorate the modal popup area element.
<a name="line298"></a>  goog.base(this, &#39;decorateInternal&#39;, element);
<a name="line299"></a>  goog.dom.classes.add(this.getElement(), this.getCssClass());
<a name="line300"></a>
<a name="line301"></a>  // Create the background mask...
<a name="line302"></a>  this.manageBackgroundDom_();
<a name="line303"></a>  this.createTabCatcher_();
<a name="line304"></a>
<a name="line305"></a>  // Make sure the decorated modal popup is hidden.
<a name="line306"></a>  goog.style.showElement(this.getElement(), false);
<a name="line307"></a>};
<a name="line308"></a>
<a name="line309"></a>
<a name="line310"></a>/** @override */
<a name="line311"></a>goog.ui.ModalPopup.prototype.enterDocument = function() {
<a name="line312"></a>  this.renderBackground_();
<a name="line313"></a>  goog.base(this, &#39;enterDocument&#39;);
<a name="line314"></a>
<a name="line315"></a>  goog.dom.insertSiblingAfter(this.tabCatcherElement_, this.getElement());
<a name="line316"></a>
<a name="line317"></a>  this.focusHandler_ = new goog.events.FocusHandler(
<a name="line318"></a>      this.getDomHelper().getDocument());
<a name="line319"></a>
<a name="line320"></a>  // We need to watch the entire document so that we can detect when the
<a name="line321"></a>  // focus is moved out of this modal popup.
<a name="line322"></a>  this.getHandler().listen(
<a name="line323"></a>      this.focusHandler_, goog.events.FocusHandler.EventType.FOCUSIN,
<a name="line324"></a>      this.onFocus_);
<a name="line325"></a>};
<a name="line326"></a>
<a name="line327"></a>
<a name="line328"></a>/** @override */
<a name="line329"></a>goog.ui.ModalPopup.prototype.exitDocument = function() {
<a name="line330"></a>  if (this.isVisible()) {
<a name="line331"></a>    this.setVisible(false);
<a name="line332"></a>  }
<a name="line333"></a>
<a name="line334"></a>  goog.dispose(this.focusHandler_);
<a name="line335"></a>
<a name="line336"></a>  goog.base(this, &#39;exitDocument&#39;);
<a name="line337"></a>  goog.dom.removeNode(this.bgIframeEl_);
<a name="line338"></a>  goog.dom.removeNode(this.bgEl_);
<a name="line339"></a>  goog.dom.removeNode(this.tabCatcherElement_);
<a name="line340"></a>};
<a name="line341"></a>
<a name="line342"></a>
<a name="line343"></a>/**
<a name="line344"></a> * Sets the visibility of the modal popup box and focus to the popup.
<a name="line345"></a> * Lazily renders the component if needed.
<a name="line346"></a> * @param {boolean} visible Whether the modal popup should be visible.
<a name="line347"></a> */
<a name="line348"></a>goog.ui.ModalPopup.prototype.setVisible = function(visible) {
<a name="line349"></a>  goog.asserts.assert(
<a name="line350"></a>      this.isInDocument(), &#39;ModalPopup must be rendered first.&#39;);
<a name="line351"></a>
<a name="line352"></a>  if (visible == this.visible_) {
<a name="line353"></a>    return;
<a name="line354"></a>  }
<a name="line355"></a>
<a name="line356"></a>  if (this.popupShowTransition_) this.popupShowTransition_.stop();
<a name="line357"></a>  if (this.bgShowTransition_) this.bgShowTransition_.stop();
<a name="line358"></a>  if (this.popupHideTransition_) this.popupHideTransition_.stop();
<a name="line359"></a>  if (this.bgHideTransition_) this.bgHideTransition_.stop();
<a name="line360"></a>
<a name="line361"></a>  if (visible) {
<a name="line362"></a>    this.show_();
<a name="line363"></a>  } else {
<a name="line364"></a>    this.hide_();
<a name="line365"></a>  }
<a name="line366"></a>};
<a name="line367"></a>
<a name="line368"></a>
<a name="line369"></a>/**
<a name="line370"></a> * Sets the transitions to show and hide the popup and background.
<a name="line371"></a> * @param {!goog.fx.Transition} popupShowTransition Transition to show the
<a name="line372"></a> *     popup.
<a name="line373"></a> * @param {!goog.fx.Transition} popupHideTransition Transition to hide the
<a name="line374"></a> *     popup.
<a name="line375"></a> * @param {!goog.fx.Transition} bgShowTransition Transition to show
<a name="line376"></a> *     the background.
<a name="line377"></a> * @param {!goog.fx.Transition} bgHideTransition Transition to hide
<a name="line378"></a> *     the background.
<a name="line379"></a> */
<a name="line380"></a>goog.ui.ModalPopup.prototype.setTransition = function(popupShowTransition,
<a name="line381"></a>    popupHideTransition, bgShowTransition, bgHideTransition) {
<a name="line382"></a>  this.popupShowTransition_ = popupShowTransition;
<a name="line383"></a>  this.popupHideTransition_ = popupHideTransition;
<a name="line384"></a>  this.bgShowTransition_ = bgShowTransition;
<a name="line385"></a>  this.bgHideTransition_ = bgHideTransition;
<a name="line386"></a>};
<a name="line387"></a>
<a name="line388"></a>
<a name="line389"></a>/**
<a name="line390"></a> * Shows the popup.
<a name="line391"></a> * @private
<a name="line392"></a> */
<a name="line393"></a>goog.ui.ModalPopup.prototype.show_ = function() {
<a name="line394"></a>  if (!this.dispatchEvent(goog.ui.PopupBase.EventType.BEFORE_SHOW)) {
<a name="line395"></a>    return;
<a name="line396"></a>  }
<a name="line397"></a>
<a name="line398"></a>  this.resizeBackground_();
<a name="line399"></a>  this.reposition();
<a name="line400"></a>
<a name="line401"></a>  // Listen for keyboard and resize events while the modal popup is visible.
<a name="line402"></a>  this.getHandler().listen(
<a name="line403"></a>      this.getDomHelper().getWindow(), goog.events.EventType.RESIZE,
<a name="line404"></a>      this.resizeBackground_);
<a name="line405"></a>
<a name="line406"></a>  this.showPopupElement_(true);
<a name="line407"></a>  this.focus();
<a name="line408"></a>  this.visible_ = true;
<a name="line409"></a>
<a name="line410"></a>  if (this.popupShowTransition_ &amp;&amp; this.bgShowTransition_) {
<a name="line411"></a>    goog.events.listenOnce(
<a name="line412"></a>        /** @type {goog.events.EventTarget} */ (this.popupShowTransition_),
<a name="line413"></a>        goog.fx.Transition.EventType.END, this.onShow, false, this);
<a name="line414"></a>    this.bgShowTransition_.play();
<a name="line415"></a>    this.popupShowTransition_.play();
<a name="line416"></a>  } else {
<a name="line417"></a>    this.onShow();
<a name="line418"></a>  }
<a name="line419"></a>};
<a name="line420"></a>
<a name="line421"></a>
<a name="line422"></a>/**
<a name="line423"></a> * Hides the popup.
<a name="line424"></a> * @private
<a name="line425"></a> */
<a name="line426"></a>goog.ui.ModalPopup.prototype.hide_ = function() {
<a name="line427"></a>  if (!this.dispatchEvent(goog.ui.PopupBase.EventType.BEFORE_HIDE)) {
<a name="line428"></a>    return;
<a name="line429"></a>  }
<a name="line430"></a>
<a name="line431"></a>  // Stop listening for keyboard and resize events while the modal
<a name="line432"></a>  // popup is hidden.
<a name="line433"></a>  this.getHandler().unlisten(
<a name="line434"></a>      this.getDomHelper().getWindow(), goog.events.EventType.RESIZE,
<a name="line435"></a>      this.resizeBackground_);
<a name="line436"></a>
<a name="line437"></a>  // Set visibility to hidden even if there is a transition. This
<a name="line438"></a>  // reduces complexity in subclasses who may want to override
<a name="line439"></a>  // setVisible (such as goog.ui.Dialog).
<a name="line440"></a>  this.visible_ = false;
<a name="line441"></a>
<a name="line442"></a>  if (this.popupHideTransition_ &amp;&amp; this.bgHideTransition_) {
<a name="line443"></a>    goog.events.listenOnce(
<a name="line444"></a>        /** @type {goog.events.EventTarget} */ (this.popupHideTransition_),
<a name="line445"></a>        goog.fx.Transition.EventType.END, this.onHide, false, this);
<a name="line446"></a>    this.bgHideTransition_.play();
<a name="line447"></a>    // The transition whose END event you are listening to must be played last
<a name="line448"></a>    // to prevent errors when disposing on hide event, which occur on browsers
<a name="line449"></a>    // that do not support CSS3 transitions.
<a name="line450"></a>    this.popupHideTransition_.play();
<a name="line451"></a>  } else {
<a name="line452"></a>    this.onHide();
<a name="line453"></a>  }
<a name="line454"></a>};
<a name="line455"></a>
<a name="line456"></a>
<a name="line457"></a>/**
<a name="line458"></a> * Shows or hides the popup element.
<a name="line459"></a> * @param {boolean} visible Shows the popup element if true, hides if false.
<a name="line460"></a> * @private
<a name="line461"></a> */
<a name="line462"></a>goog.ui.ModalPopup.prototype.showPopupElement_ = function(visible) {
<a name="line463"></a>  if (this.bgIframeEl_) {
<a name="line464"></a>    goog.style.showElement(this.bgIframeEl_, visible);
<a name="line465"></a>  }
<a name="line466"></a>  if (this.bgEl_) {
<a name="line467"></a>    goog.style.showElement(this.bgEl_, visible);
<a name="line468"></a>  }
<a name="line469"></a>  goog.style.showElement(this.getElement(), visible);
<a name="line470"></a>  goog.style.showElement(this.tabCatcherElement_, visible);
<a name="line471"></a>};
<a name="line472"></a>
<a name="line473"></a>
<a name="line474"></a>/**
<a name="line475"></a> * Called after the popup is shown. If there is a transition, this
<a name="line476"></a> * will be called after the transition completed or stopped.
<a name="line477"></a> * @protected
<a name="line478"></a> */
<a name="line479"></a>goog.ui.ModalPopup.prototype.onShow = function() {
<a name="line480"></a>  this.dispatchEvent(goog.ui.PopupBase.EventType.SHOW);
<a name="line481"></a>};
<a name="line482"></a>
<a name="line483"></a>
<a name="line484"></a>/**
<a name="line485"></a> * Called after the popup is hidden. If there is a transition, this
<a name="line486"></a> * will be called after the transition completed or stopped.
<a name="line487"></a> * @protected
<a name="line488"></a> */
<a name="line489"></a>goog.ui.ModalPopup.prototype.onHide = function() {
<a name="line490"></a>  this.showPopupElement_(false);
<a name="line491"></a>  this.dispatchEvent(goog.ui.PopupBase.EventType.HIDE);
<a name="line492"></a>};
<a name="line493"></a>
<a name="line494"></a>
<a name="line495"></a>/**
<a name="line496"></a> * @return {boolean} Whether the modal popup is visible.
<a name="line497"></a> */
<a name="line498"></a>goog.ui.ModalPopup.prototype.isVisible = function() {
<a name="line499"></a>  return this.visible_;
<a name="line500"></a>};
<a name="line501"></a>
<a name="line502"></a>
<a name="line503"></a>/**
<a name="line504"></a> * Focuses on the modal popup.
<a name="line505"></a> */
<a name="line506"></a>goog.ui.ModalPopup.prototype.focus = function() {
<a name="line507"></a>  this.focusElement_();
<a name="line508"></a>};
<a name="line509"></a>
<a name="line510"></a>
<a name="line511"></a>/**
<a name="line512"></a> * Make the background element the size of the document.
<a name="line513"></a> *
<a name="line514"></a> * NOTE(user): We must hide the background element before measuring the
<a name="line515"></a> * document, otherwise the size of the background will stop the document from
<a name="line516"></a> * shrinking to fit a smaller window.  This does cause a slight flicker in Linux
<a name="line517"></a> * browsers, but should not be a common scenario.
<a name="line518"></a> * @private
<a name="line519"></a> */
<a name="line520"></a>goog.ui.ModalPopup.prototype.resizeBackground_ = function() {
<a name="line521"></a>  if (this.bgIframeEl_) {
<a name="line522"></a>    goog.style.showElement(this.bgIframeEl_, false);
<a name="line523"></a>  }
<a name="line524"></a>  if (this.bgEl_) {
<a name="line525"></a>    goog.style.showElement(this.bgEl_, false);
<a name="line526"></a>  }
<a name="line527"></a>
<a name="line528"></a>  var doc = this.getDomHelper().getDocument();
<a name="line529"></a>  var win = goog.dom.getWindow(doc) || window;
<a name="line530"></a>
<a name="line531"></a>  // Take the max of document height and view height, in case the document does
<a name="line532"></a>  // not fill the viewport. Read from both the body element and the html element
<a name="line533"></a>  // to account for browser differences in treatment of absolutely-positioned
<a name="line534"></a>  // content.
<a name="line535"></a>  var viewSize = goog.dom.getViewportSize(win);
<a name="line536"></a>  var w = Math.max(viewSize.width,
<a name="line537"></a>      Math.max(doc.body.scrollWidth, doc.documentElement.scrollWidth));
<a name="line538"></a>  var h = Math.max(viewSize.height,
<a name="line539"></a>      Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight));
<a name="line540"></a>
<a name="line541"></a>  if (this.bgIframeEl_) {
<a name="line542"></a>    goog.style.showElement(this.bgIframeEl_, true);
<a name="line543"></a>    goog.style.setSize(this.bgIframeEl_, w, h);
<a name="line544"></a>  }
<a name="line545"></a>  if (this.bgEl_) {
<a name="line546"></a>    goog.style.showElement(this.bgEl_, true);
<a name="line547"></a>    goog.style.setSize(this.bgEl_, w, h);
<a name="line548"></a>  }
<a name="line549"></a>};
<a name="line550"></a>
<a name="line551"></a>
<a name="line552"></a>/**
<a name="line553"></a> * Centers the modal popup in the viewport, taking scrolling into account.
<a name="line554"></a> */
<a name="line555"></a>goog.ui.ModalPopup.prototype.reposition = function() {
<a name="line556"></a>  // TODO(user): Make this use goog.positioning as in goog.ui.PopupBase?
<a name="line557"></a>
<a name="line558"></a>  // Get the current viewport to obtain the scroll offset.
<a name="line559"></a>  var doc = this.getDomHelper().getDocument();
<a name="line560"></a>  var win = goog.dom.getWindow(doc) || window;
<a name="line561"></a>  if (goog.style.getComputedPosition(this.getElement()) == &#39;fixed&#39;) {
<a name="line562"></a>    var x = 0;
<a name="line563"></a>    var y = 0;
<a name="line564"></a>  } else {
<a name="line565"></a>    var scroll = this.getDomHelper().getDocumentScroll();
<a name="line566"></a>    var x = scroll.x;
<a name="line567"></a>    var y = scroll.y;
<a name="line568"></a>  }
<a name="line569"></a>
<a name="line570"></a>  var popupSize = goog.style.getSize(this.getElement());
<a name="line571"></a>  var viewSize = goog.dom.getViewportSize(win);
<a name="line572"></a>
<a name="line573"></a>  // Make sure left and top are non-negatives.
<a name="line574"></a>  var left = Math.max(x + viewSize.width / 2 - popupSize.width / 2, 0);
<a name="line575"></a>  var top = Math.max(y + viewSize.height / 2 - popupSize.height / 2, 0);
<a name="line576"></a>  goog.style.setPosition(this.getElement(), left, top);
<a name="line577"></a>
<a name="line578"></a>  // We place the tab catcher at the same position as the dialog to
<a name="line579"></a>  // prevent IE from scrolling when users try to tab out of the dialog.
<a name="line580"></a>  goog.style.setPosition(this.tabCatcherElement_, left, top);
<a name="line581"></a>};
<a name="line582"></a>
<a name="line583"></a>
<a name="line584"></a>/**
<a name="line585"></a> * Handles focus events.  Makes sure that if the user tabs past the
<a name="line586"></a> * elements in the modal popup, the focus wraps back to the beginning, and that
<a name="line587"></a> * if the user shift-tabs past the front of the modal popup, focus wraps around
<a name="line588"></a> * to the end.
<a name="line589"></a> * @param {goog.events.BrowserEvent} e Browser&#39;s event object.
<a name="line590"></a> * @private
<a name="line591"></a> */
<a name="line592"></a>goog.ui.ModalPopup.prototype.onFocus_ = function(e) {
<a name="line593"></a>  if (this.backwardTabWrapInProgress_) {
<a name="line594"></a>    this.resetBackwardTabWrap_();
<a name="line595"></a>  } else if (e.target == this.tabCatcherElement_) {
<a name="line596"></a>    goog.Timer.callOnce(this.focusElement_, 0, this);
<a name="line597"></a>  }
<a name="line598"></a>};
<a name="line599"></a>
<a name="line600"></a>
<a name="line601"></a>/**
<a name="line602"></a> * Moves the focus to the modal popup.
<a name="line603"></a> * @private
<a name="line604"></a> */
<a name="line605"></a>goog.ui.ModalPopup.prototype.focusElement_ = function() {
<a name="line606"></a>  try {
<a name="line607"></a>    if (goog.userAgent.IE) {
<a name="line608"></a>      // In IE, we must first focus on the body or else focussing on a
<a name="line609"></a>      // sub-element will not work.
<a name="line610"></a>      this.getDomHelper().getDocument().body.focus();
<a name="line611"></a>    }
<a name="line612"></a>    this.getElement().focus();
<a name="line613"></a>  } catch (e) {
<a name="line614"></a>    // Swallow this. IE can throw an error if the element can not be focused.
<a name="line615"></a>  }
<a name="line616"></a>};
<a name="line617"></a>
<a name="line618"></a>
<a name="line619"></a>/** @override */
<a name="line620"></a>goog.ui.ModalPopup.prototype.disposeInternal = function() {
<a name="line621"></a>  goog.dispose(this.popupShowTransition_);
<a name="line622"></a>  this.popupShowTransition_ = null;
<a name="line623"></a>
<a name="line624"></a>  goog.dispose(this.popupHideTransition_);
<a name="line625"></a>  this.popupHideTransition_ = null;
<a name="line626"></a>
<a name="line627"></a>  goog.dispose(this.bgShowTransition_);
<a name="line628"></a>  this.bgShowTransition_ = null;
<a name="line629"></a>
<a name="line630"></a>  goog.dispose(this.bgHideTransition_);
<a name="line631"></a>  this.bgHideTransition_ = null;
<a name="line632"></a>
<a name="line633"></a>  goog.base(this, &#39;disposeInternal&#39;);
<a name="line634"></a>};
</pre>


</body>
</html>
